import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;

import javax.swing.*;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class Main {
    public static void main(String[] args) throws InterruptedException {

        test11();

    }



    private static void test11() throws InterruptedException {
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        //打开百度页面
        webDriver.get("https://www.baidu.com/");
        //搜索框输入软件测试
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("软件测试");

        //在键盘上按下Ctrl+A
        webDriver.findElement(By.cssSelector("#kw")).sendKeys(Keys.CONTROL+"A");
        sleep(3000);
        //键盘按下Ctrl+X
        webDriver.findElement(By.cssSelector("#kw")).sendKeys(Keys.CONTROL+"X");
        sleep(3000);
        //键盘按下Ctrl+V
        webDriver.findElement(By.cssSelector("#kw")).sendKeys(Keys.CONTROL+"V");
        sleep(3000);
        webDriver.findElement(By.cssSelector("#su")).click();
    }

    private static void test10() throws InterruptedException {

        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        //打开百度页面
        webDriver.get("https://www.baidu.com/");
        //搜索框输入软件测试
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("软件测试");
        //点击百度一下
        webDriver.findElement((By.cssSelector("#su"))).click();
        sleep(3000);
        //浏览器返回
        webDriver.navigate().back();
        sleep(3000);
        //浏览器前进
        webDriver.navigate().forward();
        sleep(3000);
        //浏览器刷新
        webDriver.navigate().refresh();


    }

    private static void  test09(){
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
       // webDriver.manage().window().maximize();//浏览器窗口最大化
       // webDriver.manage().window().fullscreen();//浏览器全屏
        webDriver.manage().window().setSize(new Dimension(500,500));//设置窗口大小

    }

    private static void test08(){
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
       String title= webDriver.getTitle();
        System.out.println(title);
        if(title.equals("百度一下，你就知道")){
            System.out.println("测试通过");
        }else{
            System.out.println("测试不通过");
        }
        webDriver.quit();

    }
    private static void test07(){
        //打开百度并获取百度url
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        String url= webDriver.getCurrentUrl();
        System.out.println(url);
        if(url.equals("https://www.baidu.com/")){
            System.out.println("测试通过");
        }else{
            System.out.println("测试不通过");
        }
        webDriver.quit();
    }

    private static void test06(){
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("测试");
        webDriver.findElement(By.cssSelector("#su")).click();
        //等待3秒后清空
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        webDriver.findElement(By.cssSelector("#kw")).clear();

    }

    private static void test05() throws InterruptedException {
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("测试");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        webDriver.findElement(By.cssSelector("#kw")).clear();



    }






    private static void test04() {
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#s-top-left > a:nth-child(4)")).click();


    }

    private static void test03() throws InterruptedException {
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver=new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        System.out.println(webDriver.findElement(By.cssSelector("#su")).getAttribute("value"));
    }


    private static void test02() throws InterruptedException {
        //创建一个驱动
        ChromeOptions options=new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");//赋予权限
       WebDriver webDriver=new ChromeDriver(options);
        //打开百度页面
        webDriver.get("https://www.baidu.com/");
        //输入软件测试，并点击搜索
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("软件测试");
        webDriver.findElement(By.xpath("//*[@id=\"su\"]")).click();
        sleep(4000);
        WebElement webElements=webDriver.findElement(By.cssSelector("em"));
        System.out.println(webElements.getSize());

        if(webElements.getSize().equals("0,0")){
            System.out.println("测试不通过");
        }else{
            System.out.println("测试通过");
        }

    }
}